<!--
* @description:领用申请
* @fileName: RecipientsToApplyFor
* @author:孟帅龙
* @date:2021-1-14
* @后台人员:孟帅龙
-->
<template>
  <div>
    <!-- 领用申请 -->
    <div class="lysq">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="150px"
        class="demo-ruleForm"
      >
        <el-form-item label="标题：" prop="Headlinek">
          <el-input
            v-model="ruleForm.Headlinek"
            placeholder="请输入领用标题"
          ></el-input>
        </el-form-item>
        <el-form-item label="用途描述：" prop="UseDescribes">
          <el-input type="textarea" v-model="ruleForm.UseDescribes"></el-input>
        </el-form-item>
        <el-form-item label="备注：" prop="Remarkm">
          <el-input type="textarea" v-model="ruleForm.Remarkm"></el-input>
        </el-form-item>
        <el-form-item label="领用物品：" prop="RecipientsItems">
          <el-input
            v-model="ruleForm.RecipientsItems"
            placeholder="请输入领用物品"
          ></el-input>
        </el-form-item>
        <el-form-item label="领用人：" prop="Recipient">
          <el-input
            v-model="ruleForm.Recipient"
            placeholder="请输入领用人"
          ></el-input>
        </el-form-item>
        <el-form-item label="审批人：" prop="Approverk">
          <el-input
            v-model="ruleForm.Approverk"
            placeholder="请输入审批人"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >提交</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
          <el-button @click="fanhui">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        RecipientsToApplyNumber: "",
        Headlinek: "",
        UseDescribes: "",
        Remarkm: "",
        RecipientsItems: "",
        Recipient: "",
        Approverk: "",
      },
      rules: {
        RecipientsToApplyNumber: [
          { required: true, message: "请输入编号", trigger: "blur" },
        ],
        Headlinek: [{ required: true, message: "请输入标题", trigger: "blur" }],
        UseDescribes: [
          { required: true, message: "请填写用途描述", trigger: "blur" },
        ],
        Remarkm: [{ required: true, message: "请填写备注", trigger: "blur" }],
        RecipientsItems: [
          { required: true, message: "请填写领用物品", trigger: "blur" },
        ],
        Recipient: [
          { required: true, message: "请填写领用人", trigger: "blur" },
        ],
        Approverk: [
          { required: true, message: "请填写审批人", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios
            .post(
              "https://localhost:44399/api/app/recipients-to-appls/add-recipients-to-appls",
              this.ruleForm
            )
            .then((res) => {
              if (res.data > 0) {
                this.$message.success("添加成功");
                this.fanhui();
              } else {
                this.$message.success("添加失败");
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    fanhui() {
      this.$router.push("/AidRecipients");
    },
  },
};
</script>

<style>
.lysq {
  width: 500px;
  margin: 50px;
}
</style>